package com.wu.llpsw.HUD;

import com.wu.llpsw.yuanli.energy.hubShowYuanLi;
import com.wu.llpsw.yuanli.energy.yuanliManager;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.world.entity.player.Player;
import com.wu.llpsw.data.levelData;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

import java.awt.font.FontRenderContext;
@OnlyIn(Dist.CLIENT)
public class energyHUD  extends GuiComponent {
    private final int X;
    private final int Y;
    int bgTexturesWidth=7;//70;
    int bgTexturesHeight=8;//12;
    private  int uvWidth=70;
    private  int uvHeight=7;
    private final Minecraft minecraft;
    private static final ResourceLocation HUD = new ResourceLocation("wu", "textures/gui/hud.png");
    private final PoseStack poseStack;
    public energyHUD(PoseStack input){
        this.minecraft = Minecraft.getInstance();
        //this.Y=210;
        //this.X=10;
        this.Y=Minecraft.getInstance().getWindow().getGuiScaledHeight()-22;
        this.X=Minecraft.getInstance().getWindow().getGuiScaledWidth()/2+64;
        double scale=Minecraft.getInstance().getWindow().getGuiScale();
        if(scale<1.0d){
            uvWidth=(int)scale*70/2;
            uvHeight=(int)scale*7/2;
            //bgTexturesWidth=(int)scale*70/2;
            //bgTexturesHeight=(int)scale*12/2;
        }
        else {
            uvWidth=70;
            uvHeight=7;
            //bgTexturesWidth=70;
            //bgTexturesHeight=12;
        }

        this.poseStack = input;
    }
    public void allBgRender() {
        int startTexturesX=0;
        int startTexturesY=0;
        //绑定滤镜
        RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
        //绑定贴图
        RenderSystem._setShaderTexture(0,HUD);

        //生成蓝条背景
        blit(poseStack, X+30, Y+10, startTexturesX, startTexturesY, uvWidth,uvHeight,bgTexturesWidth, bgTexturesHeight);

    }



    public void energyRender(){
        int startTexturesX=0;
        int startTexturesY=0;
        //计算百分比
        //double mid=yuanliManager.getNowYuanLi(player)*100.00d/yuanliManager.getMaxYuanLi(player);
        double mid= hubShowYuanLi.getnow()*100.00d/hubShowYuanLi.getmax();
        float p=(float) mid/100.00f;
        if (p>0.0f){
            //绑定滤镜
            RenderSystem.setShaderColor(0.0F, 1.0F, 1.0F, 1.0F);
            //绑定贴图
            RenderSystem._setShaderTexture(0,HUD);
            blit(poseStack,X+30,Y+10,startTexturesX,startTexturesY,(int)(uvWidth*p),uvHeight,bgTexturesWidth,bgTexturesHeight);
        }
    }

    public void levelWordRender(Player player){
        //绑定滤镜

        RenderSystem.setShaderColor(0.00F, 0.00F, 0.000F, 1.0F);
        //显示数据
        drawString(poseStack,minecraft.font,hubShowYuanLi.getnow()+"",X+30+uvWidth,Y+9,0xFFFF00);
        drawCenteredString(poseStack,minecraft.font,levelData.getLevelName(player.experienceLevel),X+60,Y-10,0x800080);
    }
}
